// ActionScript file
import com.helloniu.wb.containers.ShapeTypeDef;
import com.helloniu.wb.tools.DrawingTool;
import com.helloniu.wb.tools.LineTool;
import com.helloniu.wb.tools.PencileTool;
import com.helloniu.wb.tools.TextTool;
import com.helloniu.view.widget.StyleEditorImpl;
import com.helloniu.data.wb.WBStyle;
import com.helloniu.fl.util.Tool;

private var selectedTool:DrawingTool = null;

public function setSelectedItem(dtool:DrawingTool = null):void {
	selectedTool = dtool;

	if(dtool == null) {
		this.visible = false;
		return;
	}

	this.visible = true;

	if((dtool is LineTool) || (dtool is PencileTool)) {
		this.selectedIndex = 0;
	}
	else if(dtool is TextTool) {
		this.selectedIndex = 2;
	}
	else {
		this.selectedIndex = 1;
	}

	setWBStyle(selectedTool.getWBStyle());
}

public function setSelectedTool(val:Number = NaN):void {
	if(isNaN(val) || val == ShapeTypeDef.LASER) {
		this.visible = false;
		return;
	}
	
	this.visible = true;
	
	if((val == ShapeTypeDef.LINE) || (val == ShapeTypeDef.PENCILE)) {
		this.selectedIndex = 0;
	}
	else if(val == ShapeTypeDef.TEXT) {
		this.selectedIndex = 2;
	}
	else {
		this.selectedIndex = 1;
	}
}

public function getWBStyle():WBStyle {
	if(!this.visible) {
		return null;
	}
	
	return (this.selectedChild as StyleEditorImpl).getWBStyle();
}

public function setWBStyle(awbstyle:WBStyle):void {
	if(!this.visible) {
		Tool.alert("===editors is not ready==");
		return;
	}
	
	if(this.selectedChild == null) {
		Tool.alert("===editors is not ready ==2==");
	}

	(this.selectedChild as StyleEditorImpl).setWBStyle(awbstyle);
}

public function populate():void {
}